package web;

import service.UserService;
import service.impl.UserServiceImpl;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

@WebServlet("/deleteServlet")
public class DeleteServlet extends HttpServlet {

    @Override
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        doGet(request, response);
    }

    @Override
    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        //获取前端页面的数据,有参数
        String id = request.getParameter("id");
        //将数据创术给业务层
        UserService service = new UserServiceImpl();
        boolean boo = service.deleteById(id);
        //判断是否删除成功
        if (boo){
            response.sendRedirect("/queryListServlet");
        }else {
            request.setAttribute("msg","删除失败");
            request.getRequestDispatcher("/error").forward(request,response);
        }
    }
}
